using I2.Loc;
using UnityEngine;

public class PlayerInLeaderBoardPanel : MonoBehaviour
{
	[SerializeField]
	private GameObject oddBackground;

	[SerializeField]
	private GameObject evenBackground;

	[SerializeField]
	private GameObject myBackground;

	[SerializeField]
	private UILabel placeLabel;

	[SerializeField]
	private UILabel loginLabel;

	[SerializeField]
	private UILabel leagueLabel;

	[SerializeField]
	private UILabel starsLabel;

	[SerializeField]
	private GameObject myPlace;

	private LeaderInfo _playerInfo;

	private string _locKeyLeague;

	private void OnEnable()
	{
		if (!string.IsNullOrEmpty(_locKeyLeague))
		{
			leagueLabel.text = ScriptLocalization.Get(_locKeyLeague);
		}
	}

	public void Init(LeaderInfo player)
	{
		_playerInfo = player;
		placeLabel.text = player.place.ToString();
		loginLabel.text = player.nickName;
		_locKeyLeague = "Game_Common/" + player.league;
		leagueLabel.text = ScriptLocalization.Get(_locKeyLeague);
		starsLabel.text = player.stars.ToString();
		ActiveBackground();
		if ((bool)myPlace && _playerInfo.me)
		{
			GetComponent<UIWidget>().OnVisibilityChange += ShowHideMyPlace;
		}
	}

	public void HideLeagueLabel()
	{
		leagueLabel.gameObject.SetActive(false);
	}

	private void ActiveBackground()
	{
		if (_playerInfo.me)
		{
			myBackground.SetActive(true);
		}
		else if (_playerInfo.place % 2 == 0)
		{
			evenBackground.SetActive(true);
		}
		else
		{
			oddBackground.SetActive(true);
		}
	}

	private void ShowHideMyPlace(bool visible)
	{
		if (base.transform.position.y < 0f)
		{
			myPlace.SetActive(!visible);
		}
	}
}
